package com.cxhc.app.api;


import com.cxhc.app.api.mapper.RpFeedbackMapStructMapper;
import com.cxhc.app.api.vo.RpFeedbackVo;
import com.cxhc.common.annotation.Anonymous;
import com.cxhc.common.core.controller.BaseController;
import com.cxhc.common.core.domain.AjaxResult;
import com.cxhc.common.core.domain.R;
import com.cxhc.common.core.page.TableDataInfo;
import com.cxhc.common.utils.SecurityUtils;
import com.cxhc.system.domain.app.RpAttendRecord;
import com.cxhc.system.domain.cockpit.RpFeedback;
import com.cxhc.system.domain.cockpit.RpFeedbackFlow;
import com.cxhc.system.mapper.cockpit.RpFeedbackFlowMapper;
import com.cxhc.system.service.cockpit.IRpFeedbackService;
import com.github.pagehelper.PageHelper;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 联勤事件
 */
@RestController()
@RequestMapping("/api/feedback")
@ApiOperation("/api/feedback")
@CrossOrigin(origins = "*", maxAge = 3600)
public class ApiRpFeedback extends BaseController {


    @Resource
    private IRpFeedbackService rpFeedbackService;

    @Resource
    private RpFeedbackFlowMapper rpFeedbackFlowMapper;



    /**
     * 查询报修列表
     */
    @RequestMapping("/list")
    public TableDataInfo list(@RequestBody RpFeedbackVo rpFeedbackVo)
    {
        RpFeedback rpFeedback = RpFeedbackMapStructMapper.INSTANCE.RpFeedbackVoToRpFeedback(rpFeedbackVo);
        PageHelper.startPage(rpFeedbackVo.getPageNum(),rpFeedbackVo.getPageSize(),"AddTime desc");
        List<RpFeedback> list = rpFeedbackService.selectRpFeedbackList(rpFeedback);
        return getDataTable(list);
    }

    /**
     * 新增联勤记录
     */
    @PostMapping("/insert")
    @Anonymous
    public AjaxResult add(@RequestBody RpFeedbackVo rpFeedbackVo)
    {
        RpFeedback rpFeedback = RpFeedbackMapStructMapper.INSTANCE.RpFeedbackVoToRpFeedback(rpFeedbackVo);
        rpFeedback.setUserId(SecurityUtils.loginUserId());
        return toAjax(rpFeedbackService.insertRpFeedback(rpFeedback));
    }

    /**
     * 新增联勤记录
     */
    @PostMapping("/update")
    public AjaxResult update(@RequestBody RpFeedbackVo rpFeedbackVo)
    {
        RpFeedback rpFeedback = RpFeedbackMapStructMapper.INSTANCE.RpFeedbackVoToRpFeedback(rpFeedbackVo);
        return toAjax(rpFeedbackService.updateRpFeedback(rpFeedback));
    }

    /**
     * 流转
     */
    @PostMapping("/transfer")
    public AjaxResult transfer(@RequestBody RpFeedbackFlow rpFeedbackFlow)
    {
        return toAjax(rpFeedbackService.transfer(rpFeedbackFlow));
    }

    /**
     * 退回
     */
    @PostMapping("/back")
    public AjaxResult back(@RequestBody RpFeedbackFlow rpFeedbackFlow)
    {
        return toAjax(rpFeedbackService.back(rpFeedbackFlow));
    }

    /**
     * 受理
     */
    @PostMapping("/acceptance")
    public AjaxResult acceptance(@RequestBody RpFeedbackFlow rpFeedbackFlow)
    {
        return toAjax(rpFeedbackService.acceptance(rpFeedbackFlow));
    }

    /**
     * 完修
     */
    @PostMapping("/over")
    public AjaxResult over(@RequestBody RpFeedbackFlow rpFeedbackFlow)
    {
        return toAjax(rpFeedbackService.over(rpFeedbackFlow));
    }

    /**
     * 获取报修详细信息
     */
    @GetMapping(value = "/details/{ID}")
    public AjaxResult getInfo(@PathVariable("ID") Long ID)
    {
        return success(rpFeedbackService.selectRpFeedbackByIDForApp(ID));
    }

}
